package com.ls.callabel;


import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

class MyThread1 implements Runnable{
    @Override
    public void run() {
        System.out.println("run");
    }
}
class MyThread2 implements Callable {
    @Override
    public Integer call() throws Exception {
        return 200;
    }
}
public class Demo1 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //Runnable
        new Thread(new MyThread1(),"aa").start();
        //Callable
        //new Thread(new MyThread2(),"aa").start(); --不正确
        FutureTask<Integer> task = new FutureTask<>(new MyThread2());

        FutureTask<Integer> task1 = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName() + " come in callable");
            return 1024;
        });

        new Thread(task1, "bb").start();
        while (!task1.isDone()){
            System.out.println("wait!");
        }

        System.out.println(task1.get());
    }

}
